
const sm4 = require("sm-crypto").sm4;
const key = "37eaeace4c44dc13703eddace66950b6"; // 可以为 16 进制串或字节数组，要求为 128 比特
export function encrypt(text) {
  return hexToBase64(sm4.encrypt(text, key));
}
export function decrypt(text) {
  return sm4.decrypt(text, key);
}

function hexToBase64(hexString) {
  var str = "";
  for (var i = 0; i < hexString.length; i += 2) {
    str += String.fromCharCode(parseInt(hexString.substr(i, 2), 16));
  }
  return btoa(str);
}
